<template>
  <div class="song-list">
			<ul>
				<li @click="selectItem(song, index)" class="item" v-for="(song, index) in songs" :key="index">
					<div class="rank" v-show="rank">
						<span :class="getRankCls(index)" v-text="getRankText(index)"></span>
					</div>
					<div class="content">
						<h2 class="name">{{song.name}}</h2>
						<p class="desc">{{getDesc(song)}}</p>
					</div>
				</li>
			</ul>
  </div>
</template>

<script>
export default {
  name: 'songlist',
	data() {
		return {
			so: []
		}
	},
	props: {
		songs: {
			type: Array,
			default:function () { //数组和对象的默认值 必须是一个工厂函数
				 return []
			}
		},
		rank: {//排行
			type: Boolean,
			default: false
		}
	},
	methods:{
		selectItem(item, index) {//判断歌曲是否有歌词歌曲信息
			 this.$emit('select', item, index)
		},
		getDesc(song){//歌手信息
			return `${song.singer}`
		},
		getRankCls(index) {//奖杯图片
			if (index <= 2) {
				return `icon icon${index}`
			} else {
				return 'text'
			}
		},
		getRankText(index) {
			if (index > 2) {
				return index + 1
			}
		}
	}
}
</script>

<style lang="scss" scoped >
		.song-list{
			.item{
				display: flex;
				align-items: center;
				box-sizing: border-box;
				height: 64px;
				font-size: $font-size-medium;
				.rank{
					flex: 0 0 25px;
					width: 25px;
					margin-right:30px;
					text-align: center;
					.icon{
						display: inline-block;
						width: 25px;
						height: 24px;
						background-size:25px 24px;
						&.icon0{ @include bg-image('img/first')}
						&.icon1{ @include bg-image('img/second')}
						&.icon2{ @include bg-image('img/third')}
					}
					.text{
						color: $color-theme;
						font-size: $font-size-large;
					}
				}
			}
			.content{
				flex: 1;
				line-height: 20px;
				overflow: hidden;
				.name{
					@include no-wrap();
					color: $color-text;
				}
				.desc{
					@include no-wrap();
          margin-top: 4px;
          color: $color-text-d;
				}
			}
		}
</style>